﻿//========================================================= 
/**@file WinBluetoothIC_DevUpdater.h
 * @brief Windows下蓝牙接口设备固件升级程序
 * 
 * @date 2017-01-21   15:35:41
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_WINBLUETOOTHIC_DEVUPDATER_H_
#define _LIBZHOUYB_WINBLUETOOTHIC_DEVUPDATER_H_
//--------------------------------------------------------- 
#include "COM_IC_DevUpdater.h"

#include "../../test_frame/linker/WinBluetoothTestLinker.h"
using zhou_yb::application::test::WinBluetoothTestLinker;
//--------------------------------------------------------- 
namespace zhou_yb {
namespace application {
namespace updater {
//--------------------------------------------------------- 
/// Windows下串口设备检测升级状态连接器
template<class TBluetoothDevice>
class WinBluetoothUpdateModeTestLinker : public TestLinker<TBluetoothDevice>
{
protected:
    //----------------------------------------------------- 
    WinBluetoothTestLinker<TBluetoothDevice> _linker;
    //----------------------------------------------------- 
public:
    //----------------------------------------------------- 
    /**
     * @brief 扫描蓝牙,并发送升级切换指令
     * 
     * @param [in] dev 需要操作的设备
     * @param [in] arg 参数列表
     * - 参数:
     *  - Name : string 需要连接的蓝牙名称
     *  - Address : string 需要连接的蓝牙地址
     * .
     * @param [in] printer 文本输出器
     */
    virtual bool Link(TBluetoothDevice& dev, IStringArguments& arg, TextPrinter& printer)
    {
        if(!_linker.Link(dev, arg, printer))
            return false;
        
        if(ComUpdateModeSwitcher::IsUpgradeMode(dev))
            return true;

        ComUpdateModeSwitcher::ToUpgradeMode(dev);
        _linker.UnLink(dev, printer);
        return false;
    }
    /// 关闭串口
    virtual bool UnLink(TBluetoothDevice& dev, TextPrinter& printer)
    {
        return _linker.UnLink(dev, printer);
    }
    //----------------------------------------------------- 
};
//--------------------------------------------------------- 
} // namespace updater
} // namespace application
} // namespace zhou_yb
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_WINBLUETOOTHIC_DEVUPDATER_H_
//========================================================= 